import stackless
from pyglet.window import key


class Input(object):
    """Base class of all input devices.

    Takes a channel for x and z in a physics.SpaceShip()
    and sends the values for x and z directions between
    -1.0 and 1.0"""
    def __init__(self, quit):
        self.quit = quit

    def process_events(self):
        pass

    def fire(self):
        pass


class Keyboard(Input):
    def __init__(self, win, quit):
        self.axes = [0,0]
        self.thrust = 0
        self.win = win
        self.quit = quit
        self.win.on_key_press = self.on_key_press
        self.win.on_key_release = self.on_key_release

    def on_key_press(self, symbol, modifiers):
        if symbol == key.UP:
            self.axes[1] = -1.0
        elif symbol == key.DOWN:
            self.axes[1] = 1.0
        if symbol == key.LEFT:
            self.axes[0] = 1.0
        elif symbol == key.RIGHT:
            self.axes[0] = -1.0
        if symbol == key.PLUS:
            self.thrust = -1.0 #-z into screen
        elif symbol == key.MINUS:
            self.thrust = 1.0
        if symbol == key.ESCAPE:
            self.quit()

    def on_key_release(self, symbol, modifiers):
        if symbol in (key.UP, key.DOWN):
            self.axes[1] = 0
        if symbol in (key.LEFT, key.RIGHT):
            self.axes[0] = 0
        if symbol in (key.PLUS, key.MINUS):
            self.thrust = 0
        
